<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1.定义一个 bookOne 对象，包含 title、author、price、serialNumber 属性
        // 复制这个对象到另一本书bookTwo 里，仅改变serialNumber，改变bookTwo某个属性
        // 打印输出两个对象，并观察他们的异同
        let bookOne = {
            title : "《张三的故事》",
            author : "张三",
            price : "￥59.9",
            serialNumber : 1,
            obj : {a : 1, b : 4, c : 5},
            fn : function () {
                console.log("ABC出版社")
            }
        }
        console.log(bookOne["title"])
        
        let bookTwo = JSON.parse(JSON.stringify(bookOne))
        bookTwo.author = "李四"
        console.log(bookTwo)
        console.log(bookOne)

        function deepCopy(obj) {
            let newObj = {};
            if (typeof obj != "object") {
                return obj;
            }
            for (let key in obj) {
                newObj[key] = deepCopy(obj[key])
            }
            return newObj;
        }
        let book = deepCopy(bookOne)
        book.obj.a = 2
        book.fn = function () {
            console.log("BBC出版社")
        }
        console.log(book)
        book.fn()
        console.log(bookOne)
        bookOne.fn()
    </script>
</body>
</html>